<?php


namespace App\Utils;


class LevelRule
{
    public static $rule = [
        '1' => [
            'priceLimit' => 0.5,//可做任务价格限制
            'goldMin' => 0,//最小金币数
            'goldMax' => 50//最大金币数
        ],
        '2' => [
            'priceLimit' => 2,
            'goldMin' => 50,
            'goldMax' => 200
        ],
        '3' => [
            'priceLimit' => 5,
            'goldMin' => 200,
            'goldMax' => 500
        ],
        '4' => [
            'priceLimit' => 10,
            'goldMin' => 500,
            'goldMax' => 1000
        ],
        '5' => [
            'priceLimit' => 9999999999,//可做任何任务
            'goldMin' => 1000,
            'goldMax' => 2000//默认给个最大值
        ]
    ];

    public static function text()
    {
//        $canDoTmpl = "%s元以内";
//        $upgradeTmpl = "赚得%s个金币后升级";
//
//        $text = [];
//        foreach (self::$rule as $k => $v) {
//            if ($k < 5) {
//                $tmp = [
//                    'value' => $k,
//                    'goldMax' => $v['goldMax'],
//                    'canDo' => sprintf($canDoTmpl, $v['priceLimit']),
//                    'upgrade' => sprintf($upgradeTmpl, $v['goldMax'])
//                ];
//                array_push($text, $tmp);
//            }
//        }
//        array_push(
//            $text,
//            [
//                'value' => 5,
//                'goldMax' => '',
//                'canDo' => '所有任务',
//                'upgrade' => ''
//            ]
//        );
//
//        return $text;

        $text = [];
        foreach (self::$rule as $k => $v) {
            if ($k < 5) {
                $text[] = [
                    'level' => $k,
                    'upgradeGold' => $v['goldMax'],
                    'canDoPrice' => $v['priceLimit']
                ];
            } else {
                $text[] = [
                    'level' => $k,
                    'upgradeGold' => $v['goldMax'],
                    'canDoPrice' => ''
                ];
            }
        }
        return [
            'levelRule' => $text
        ];
    }
}